﻿/*
 * Copyright(C) 2012,ajayumi 保留所有权利。( All rights reserved. )
 * 
 * 文件名称：RC2CryptoProvider.cs
 * 摘    要：
 * 当前版本：1.0
 * 作    者：黄乙冬 (ajayumi)
 * 创建日期：2012年6月10日星期日
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ajayumi.Platform.Core.Security
{
    /// <summary>
    /// RC2CryptoProvider
    /// </summary>
    public class RC2CryptoProvider : SymmetricCryptoProvider
    {
        #region Variables

        /// <summary>
        /// 默认密钥
        /// </summary>
        private const string DEFAULT_KEY = "A1BC1FE843B9E5F9";

        #endregion

        public RC2CryptoProvider()
            : base("RC2CryptoProvider")
        {
        }

        protected override void Init()
        {
            if (this.SymAlg == null)
            { this.SymAlg = new RC2CryptoServiceProvider(); }

            if (string.IsNullOrEmpty(this.CryptoKey) || this.CryptoKey.Length != 16)
            {
                this.CryptoKey = DEFAULT_KEY;
            }

            this.SymAlg.Key = this.HexToByte(this.CryptoKey); 
            this.SymAlg.IV = this.SymAlg.Key;

        }
    }
}
